package com.hui.springBoot_demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * TODO: SpringBoot第一个controller
 *
 * @author chenth
 * @create 2018-07-10 17:05
 **/
@RestController
//@RestController == @Controller + @ResponseBody
public class HelloController {

    //通过@Value注解来获取配置文件的值，类型可以自己定义
    @Value("${cupSize}")
    private String cupSize;
    @Value("${age}")
    private Integer age;
    //配置文件里面使用配置
    @Value("${content}")
    private String content;
    @Value("${cupSize-dev}")
    private String cupSize_dev;
    @Value("${age-dev}")
    private Integer age_dev;
    @Resource
    private GirlProperties girlProperties;

    /**
     * 演示获取配置文件属性值
     * @return
     */
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String hello(){
//        return "cupSize : " + cupSize + " , age : " + age;
        return content;
    }

    /**
     * 演示通过分组获取配置文件的实体
     * @return
     */
    @RequestMapping(value = "/girl" , method = RequestMethod.GET)
    public String girl(){
        return "女孩的属性cupSize: " + girlProperties.getCupSize() + ",age:" + girlProperties.getAge();
    }

    /**
     * 演示获取引用配置文件里的属性
     * @return
     */
    @RequestMapping(value = "/dev",method = RequestMethod.GET)
    //@RequestMapping(value = "/dev",method = RequestMethod.GET)等同于 @GetMapping,看请求方法，还有@PostMapping等等
    public String dev(){
        return cupSize_dev + " " + age_dev;
    }

}
